<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录系统</title>
    <link rel="stylesheet" href="./css/login.css">
    <link rel="stylesheet" href="./bootstrap-3.4.1-dist/css/bootstrap.min.css">

    <script src="./js/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
    <script src="./js/global-axios.js"></script>
    <script src="./js/qs.js"></script>
    <script src="./js/api.js"></script>
    <script src="./bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
    <script src="./bootstrap-3.4.1-dist/js/bootstrapValidator.min.js"></script>
</head>

<body>

    <div id="full">
        <div id="header">
            <div>
                <h1>南海城市大脑</h1>
                <h2>渔业资源管理系统</h2>
            </div>
        </div>
        <div id="body">
            <ul>
                <li>账号密码登录</li>
                <li>手机号登录</li>
            </ul>
            <div class="long"></div>
            <div class="loginpass">
                <div class="row">
                    <div class=" body-password">
                        <form class="ONT">
                            <div class="form-group">
                                <label class=" control-label"></label>
                                <div class=" account">
                                    <input type="text" class="form-control " id="phone" name="username"
                                        placeholder="请输入账号或手机号码" /><span>0/11</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label"></label>
                                <div class="">
                                    <input type="password" class="form-control" id="password" name="password"
                                        placeholder="请输入密码" />
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="">
                                    <button type="submit" class="btn btn-info ">登录</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="body-phone">
                        <form>
                            <div class="form-group">
                                <label class="control-label"></label>
                                <div class="phonenum">
                                    <input type="text" class="form-control" name="phonename"
                                        placeholder="请输入手机号" /><span>0/11</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class=" control-label"></label>
                                <div class="">
                                    <input type="password" class="form-control" name="password" placeholder="请输入验证码" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="">
                                    <button type="submit" class="btn btn-info">手机登录</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>


            <div class="forget">
                <p class="forgetpass monik" data-toggle="modal" data-target="#myModal">忘记密码</p>
                <p><a href="./nessage.html">信息员注册</a></p>
            </div>

        </div>
        <div id="foot">
            <div class="QRCode"><img src="./img/erweima.png" alt="">
                <p>手机端二维码</p>
            </div>
        </div>
        <div id="bottom">
            <p>@copyright 2021 阿里云计算有限公司出品</p>
        </div>
    </div>


    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">忘记密码</h4>
                </div>
                <form id="defaultForm" method="post" class="form-horizontal" action="ajaxSubmit.php">

                    <div class="modal-body">
                        <div class="form-group information phonenum ">
                            <label class=" control-label">
                                <p><sup>*</sup>手机号码</p>
                            </label>
                            <div class="phonenum">
                                <input type="text" class="form-control" name="phonename"><span>0/11</span>
                            </div>
                        </div>
                        <div class="form-group information getit ">
                            <label class=" control-label">
                                <p><sup>*</sup>验证码</p>
                            </label>
                            <div class="phonenum">
                                <input type="password" class="form-control" name="password"><button
                                    class="btn btn-warning">获取验证码</button>
                            </div>
                        </div>
                        <div class="form-group information password1">
                            <label class=" control-label">
                                <p><sup>*</sup>密码</p>
                            </label>
                            <input type="password" class="form-control" name="password">
                        </div>
                        <div class="form-group information password2">
                            <label class=" control-label ">
                                <p><sup>*</sup>确认密码</p>
                            </label>
                            <input type="password" class="form-control" name="password">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-success closer">关闭</button>
                        <button type="submit" class="btn btn-primary">提交更改</button>
                    </div>
                </form>
            </div><!-- /.modal-content -->
        </div><!-- /.modal -->
    </div>
</body>

<script>
    var _this
    class Login {
        constructor(id) {
            _this = this
            this.main = document.querySelector('.loginpass');
            this.zhanghao = this.main.querySelector('.body-password')
            this.phone = this.main.querySelector('.body-phone');
            this.zhanghaolong = this.main.querySelector('.account input')
            this.phonelong = this.main.querySelector('.phonenum input')
            this.phonelong2 = document.querySelector('.modal-body .phonenum input')
            this.init()
        }
        init() {
            this.updateNode()
            this.getLonger(this.zhanghaolong, this.span)
            this.getLonger(this.phonelong, this.span2)
            this.getLonger(this.phonelong2, this.span3)
            this.trueWord()
        }
        updateNode() {
            this.span = this.zhanghao.querySelector('.account span')
            this.span2 = this.phone.querySelector('.phonenum span')
            this.span3 = document.querySelector('.modal-body .phonenum span')
            this.password1 = document.querySelector('.password1 input')
            this.password2 = document.querySelector('.password2 input')
        }
        clearNode() {
        }
        //    1.获取input输入字符长度
        getLonger(item, index) {
            item.onkeyup = () => {
                let long = item.value.length
                index.innerHTML = ''
                index.innerHTML = long + '/11'
                item.setAttribute('maxlength', '11')
            }
        }
        //2.确认密码
        trueWord() {
            this.updateNode()
            let t = document.querySelector('.glyphicon-ok')
            let f = document.querySelector('.glyphicon-remove')
            let flag
            this.password2.onkeyup = () => {
                console.log(f, t)
                if (this.password2.value === this.password1.value) {
                    // t.style.display='block'
                    // f.style.display='none'
                    this.password2.style.border = '1px green solid'
                    flag = true
                }
                else {
                    //f.style.display='block'
                    // t.style.display='none'
                    this.password2.style.border = '1px red solid'
                    flag = false
                }
            }
            this.password2.onblur = () => {
                if (flag) {
                    this.password2.style.border = '1px black solid'
                } else {
                    this.password2.style.border = '1px red solid'
                }
            }
        }
    }
    new Login('.loginpass')


    $('.ONT').on('submit',function (e){
      e.preventDefault()
      Api.login({
          username:$('#phone').val(),
          password:$('#password').val(),
      },null).then(function (res){
          console.log(res)
       // location.href = 'index.html'
      })
  })
   

    $(function () {
        //选项卡功能
        function xxk() {
            $('#body>ul li').eq(0).on('click', function () {
                $('.body-password').show();
                $('.body-phone').hide();
                $('.long').stop().animate({ left: 0 }, 500)
            })
            $('#body>ul li').eq(1).on('click', function () {
                $('.body-phone').show();
                $('.body-password').hide();
                $('.long').stop().animate({ left: 175 }, 500)
            })
        }
        xxk()
        $('.monik').on('click', function () {
            $('#myModal').show()
        })
        $('.closer').on('click', function () {
            if (confirm("是否确认关闭")) {
                $('#myModal').modal("hide")

            } else {
                $('#myModal').modal("show")
            }
        })

        $('form')
            .bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    username: {
                        message: 'The username is not valid',
                        validators: {
                            notEmpty: {
                                message: '账号不能为空'
                            },
                            stringLength: {
                                min: 3,
                                max: 11,
                                message: '账号要在3-11之间'
                            },
                            /*remote: {
                                url: 'remote.php',
                                message: 'The username is not available'
                            },*/
                            regexp: {
                                regexp: /^[a-zA-Z0-9_\.]+$/,
                                message: '账号格式错误！'
                            }
                        }
                    },
                    phonename: {
                        message: 'The username is not valid',
                        validators: {
                            notEmpty: {
                                message: '手机号号不能为空'
                            },
                            stringLength: {
                                min: 11,
                                max: 11,
                                message: '请输入正确的手机号'
                            },
                            /*remote: {
                                url: 'remote.php',
                                message: 'The username is not available'
                            },*/
                            regexp: {
                                regexp: /^[0-9]+$/,
                                message: '手机号格式错误！'
                            }
                        }
                    },
                    Chinese: {
                        message: 'The username is not valid',
                        validators: {
                            notEmpty: {
                                message: '名字不能为空'
                            },
                            // stringLength: {
                            //     min: 11,
                            //     max: 11,
                            //     message: '请输入正确的手机号'
                            // },
                            /*remote: {
                                url: 'remote.php',
                                message: 'The username is not available'
                            },*/
                            regexp: {
                                regexp: /^[\u4e00-\u9fa5]+$/,
                                message: '请输入汉字！'
                            }
                        }
                    },
                    email: {
                        validators: {
                            notEmpty: {
                                message: 'The email address is required and can\'t be empty'
                            },
                            emailAddress: {
                                message: 'The input is not a valid email address'
                            }
                        }
                    },
                    password: {
                        validators: {
                            notEmpty: {
                                message: '此项不能为空'
                            }
                        }
                    }
                }
            })
    })



</script>

</html>